/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ipark.gui.mapeditor;

import ipark.sistemski.DBConnect;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;

/**
 * class for database manipulation
 * @author jernej
 */
public class BazaMap {
    /**
     * write sections into database
     * @param edges edges will tell us in which sections they are
     * @throws java.sql.SQLException
     */
    public void writeSections(Vector<RoadEdge> edges) throws SQLException{
        //izbrišemo obstoječe sekcije
        DBConnect.statement().execute("DELETE FROM park");
        //dodamo nove sekcije
        for(int i=0;i<edges.size();i++){
            String insertQuery = "INSERT INTO park (section,nolots,repair) VALUES (?,?,0)";
            PreparedStatement ps = DBConnect.connection().prepareStatement(insertQuery);
            ps.setString(1, edges.get(i).getSection());
            ps.setInt(2, edges.get(i).getNumParkBoxes());
            ps.execute();
        }
    }
}
